package com.example.admin.service.impl;


import com.example.admin.mapper.EmpMapper;
import com.example.admin.service.EmpService;
import com.example.common.result.PageBean;
import com.example.model.emp.pojo.Employee;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceimpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, String gender, String position) {
        PageHelper.startPage(page,pageSize);
        List<Employee> list = empMapper.list(name, gender, position);
        //强转
        Page<Employee> p = (Page<Employee>) list;
        PageBean pb =  new PageBean(p.getTotal(),p.getResult());
        return pb;

    }

    @Override
    public void save(Employee employee) {
        empMapper.save(employee);
    }

    @Override
    public Employee selectById(Integer id) {
        return empMapper.selectById(id);
    }

    @Override
    public void updateById(Employee employee) {
        empMapper.updateById(employee);
    }

    /**
     * 登录获取员工信息
     * @param employee
     * @return
     */
    @Override
    public Employee getByUsernameAndPassword(Employee employee) {
        Employee emp = empMapper.getByUsernameAndPassword(employee);
        return emp;
    }

}
